<?php
/**
 * 分销日志
 * author itholiday@126.com
 */
global $_W, $_GPC;
load()->func('tpl');
$html_title = $_W['current_module']['title'];
$op = !empty($_GPC['op']) ? $_GPC['op'] : 'list';
//页面显示条数
$pagesize = 15;
$page = max(1, $_GPC['page']);
$start = ($page - 1) * $pagesize;

$where = 'A.id>0 ';

$truename = isset($_GPC['truename']) && !empty($_GPC['truename']) ? input('truename') : '';
$mobile = isset($_GPC['mobile']) && !empty($_GPC['mobile']) ? input('mobile') : '';
$start_time = isset($_GPC['start_time']) && !empty($_GPC['start_time']) ? strtotime($_GPC['start_time']) : '';
$end_time = isset($_GPC['end_time']) && !empty($_GPC['end_time']) ? strtotime($_GPC['end_time']) : '';

if (!empty($truename)) {
    $where .= " and A.truename like '%$truename%' ";
}

if (!empty($mobile)) {
    $where .= " and A.mobile like '%$mobile%' ";
}

if (!empty($start_time) && !empty($end_time)) {
    $where .= " and A.create_time>=$start_time and A.create_time<=$end_time ";
} else {
    if (!empty($start_time)) {
        $where .= " and A.create_time>=$start_time ";
    }
    if (!empty($end_time)) {
        $where .= " and A.create_time<=$start_time ";
    }
}

if ($op == 'del') {
    if (isset($_GPC['ids'])) {
        $ids = implode(',', $_GPC['ids']);
        $sql = "update ims_yq_haircircle_users set delete_time=" . time() . " where id in ($ids)";
        $res = pdo_query($sql);
        if (!empty($res)) {
            ajaxSuccess('删除成功');
        }
        ajaxError('删除失败');
    }
    if (isset($_GPC['id'])) {
        $id = $_GPC['id'];
        $res = pdo_update('yq_haircircle_users', ['delete_time' => time()], array('id' => $id));
        if (!empty($res)) {
            ajaxSuccess('删除成功');
        }
        ajaxError('删除失败');
    }
}

if ($op == 'ting' && isset($_GPC['yes'])) {
    if (isset($_GPC['id'])) {
        $id = $_GPC['id'];
        $yes = $_GPC['yes'] ? 1 : 0;
        $msg = $yes ? '启用' : '禁用';
        $res = pdo_update('yq_haircircle_users', ['user_status' => $yes], ['id' => $id]);
        if (!empty($res)) {
            ajaxSuccess($msg . '成功');
        }
        ajaxError($msg . '失败');
    }
}

if ($op == 'list' || $op == '') {

    $pagediv = 'list';

    $where .= " and A.delete_time=0 ";
    $total = pdo_fetchcolumn('SELECT COUNT(*) AS `number` FROM ' . tablename('yq_haircircle_users') . ' A WHERE ' . $where);

    //生成分页HTML
    $pager = getPageHTML($total, $page, $pagesize);
    $sql = "select A.*,B.mobile pmobile from ims_yq_haircircle_users A left join ims_yq_haircircle_users B on A.pid=B.id where $where and A.delete_time=0 order by A.id desc limit $start,$pagesize";
    $list = pdo_fetchall($sql);
    include $this->template('web/member_list');
    exit;
}